<?php

$all=$_GET["all"];

if (!$all) {$limit="limit 10";}
else {$limit="";}

include("mysql_conn.php");
include("settings.php");
$username = getenv('WEBAUTH_USER');

//get user's email
$result=mysql_query("select email from users where username='$username'");
while($row=mysql_fetch_array($result))
{
 $useremail=$row['email'];
}

//get boss' email
$result=mysql_query("select email from users where username=(select boss from users where username='$username')");
while($row=mysql_fetch_array($result))
{
 $bossemail=$row['email'];
}

function drawrestoftable($row,$useremail,$bossemail)
{
 echo "<tr>";
 echo "<td>" .  $row['creationtime'] . "</td>";
 echo "<td id='tiny'><a href='displayreport.php?reportid=" . $row['reportid'] . "'>View</a><br>
<a href='deletereport.php?reportid=" . $row['reportid'] . "'>Delete</a><br>
<a href='emailreport.php?reportid=" . $row['reportid'] . "&toperson=$bossemail'>Send to Boss</a><br>
<a href='emailreport.php?reportid=" . $row['reportid'] . "&toperson=$useremail'>Send to yourself</a></td>";
 echo "</tr>";
}


echo "<html><head><title>$site_title: My Reports</title><link rel='stylesheet' type='text/css' href='style.css'></head><body><h2>My Status Reports</h2>
User: $username<br>
<a href='myprojects.php'>My Projects</a><p>";

$result=mysql_query("select reportid, user, date_format(creationtime, '%c/%d/%Y %H:%i:%s') as creationtime from status_reports where user='$username' order by unix_timestamp(creationtime) desc $limit");

echo"<table width=50%>
<div id=tiny>Showing 10 most recent reports. <a href='myreports.php?&all=1'>Show everything</a> </div>
<tr><th>Created</th><th>Action</th>";

while($row=mysql_fetch_array($result))
{
 drawrestoftable($row,$useremail,$bossemail);
}
echo "</table><p id=tiny>(HINT #1: In Firefox or with Acrobat Pro, print to PDF and
save a copy)
<br>(HINT #2: Or save as HTML and open/save in Word as .doc)</p><hr><p>
<a href='myprojects.php'>Return to My Projects</a>
</html>";

mysql_close($con);
?>
